home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / BootingGallery.sit / Booting Gallery / Booting Gallery (source) / iconhack Folder / ShowINIT.c < prev    next >
Text File  |  1996-06-22  |  14KB  |  455 lines

  1. #define using_MacTraps 1
  2.  
  3. #if 0
  4. ; File: ShowINIT.a
  5. ; Last Modified: Sunday, November 26, 1989 05:07:56 PM
  6. ;------------------------------------------------------------------------------------------------
  7. ;
  8. ;    INIT notification routine
  9. ;     by Paul Mercer, Darin Adler, Paul Snively and Frédéric Miserey from an idea by Steve Capps
  10. ;
  11. ;    Created:  6/7/87  PM    - First version.
  12. ;    Modified: 6/15/87 PM    - Changed to standard (Pascal) calling conventions.
  13. ;          6/20/87 PM    - Fixed color & Finder bug on Mac II.
  14. ;          6/22/87 DBA    - Improved handling of QuickDraw.
  15. ;          6/29/87 DBA    - Used scratch8 to avoid conflict with “Easy Access”.
  16. ;          6/30/87 DBA    - Changed to a 4-byte scheme with “checksum”.
  17. ;          6/30/87 PFS    - Separated into ShowINIT and InnerShowINIT.
  18. ;          7/1/87  DBA    - Fixed stack bug and switched to CurApName+.
  19. ;          7/2/87  PM    - Added check for old signature in ApplScratch for
  20. ;                          backword compatibility (TMON Startup).
  21. ;          7/3/87  PM    - Removed _SysBeep in ErrorExit since it causes a crash.
  22. ;                          Also changed ICN# plotter to srcOr mode for Blinker.
  23. ;          7/13/87 PM    - Fixed a3 trashing bug in InnerShowINIT - exit code left
  24. ;                          word on stack (reported by D. Dunham).
  25. ;          7/21/87 PM    - Due to popular demand, InitGraf is no longer being called.
  26. ;                          This avoids the gamma correction problem with Startupscreens
  27. ;                          getting  “washed out” by ShowINIT though someone else is still
  28. ;                          bound to call InitGraf sooner or later (i.e. InitWindows).
  29. ;          7/29/87 PM    - Put InitGraf back in; this is required (reported by C. Derossi
  30. ;                          at Apple Tech Support).  Took out GetPort/SetPort.
  31. ;        10/06/87  PM    - Set CurrentA5 properly.  Rearranged myVars.
  32. ;        12/28/87  PM    - Major revision to accomodate future INIT31 based ShowINIT.
  33. ;        07/14/88  PM    - Major revision to get rid of above 'accomodations'.
  34. ;                          Added color icon 'cicn' support and fixed beep crash.
  35. ;                          Removed support for old signature.
  36. ;        11/25/89 FCM    - Added Y dimension support, icl48 support to get rid of 'obsolete' cicns
  37. ;         8/28/90 jbx    - Translated to Think C, added automatic x-movement determination.
  38. ;                          Removed support for 'obsolete' cicn’s.
  39. ;
  40. ;------------------------------------------------------------------------------------------------
  41. #endif
  42.  
  43. /* Originally written by Paul Mercer.  Translated to Think C by jbx. */
  44.  
  45. typedef struct {
  46.     long    Icon[32];
  47.     long    IconMask[32];
  48. } ICONList, *ICONListPtr;
  49.  
  50. #if 0
  51. extern short myVCheck    : 0x928;    /* a GREAT place to store 8 bytes (it was Darin's idea) */
  52. extern short myV        : 0x92A;
  53. extern short myH        : 0x92C;
  54. extern short myHCheck    : 0x92E;    /* a simple checksum of myH to determine first-timeness */
  55. #else
  56. static short myVCheck, myV, myH, myHCheck;
  57. #endif
  58.  
  59. enum {
  60.     firstX            =    8,            /* X coordinate of first icon to be drawn        */
  61.     bottomEdge        =    8+32,        /* this far from bottom of screen                */
  62.     iconWidth        =    32,            /* size of icon (square normally)                */
  63.     defaultMoveX    =    40,            /* x default amount to move icons                */
  64.     defaultMoveY    =    40,            /* y icon line height                            */
  65.     checksumConst    =    0x1021,        /* constant used for computing checksum            */
  66.  
  67.     iconRowBytes    =    32/8,        /* 32/8 bits                                    */
  68.  
  69.     hasCQDBit        =    6,            /* this bit in ROM85 is cleared if Color QuickDraw is available */
  70.  
  71.     iconID            =    6+4,        /* positive stackframe objects */
  72.     moveX            =    4+4,        /* horizontal distance between ShowINIT icons. */
  73.     showINITArgs    =    4,
  74.  
  75.     iconPtr            =    6+4,
  76.     initDrawArgs    =    6,
  77.  
  78.     iclPtrHdl        =    12+4,
  79.     iclDepth        =    10+4,
  80.     initDrawXArgs    =    initDrawArgs+6
  81. };
  82.  
  83. #ifndef using_MacTraps
  84. static struct {
  85.     char    qd_privates[76];    /* known only to Apple and MacWEEK... */
  86.     long    qd_randSeed;
  87.     BitMap    qd_screenBits;
  88.     Cursor    qd_arrow;
  89.     Pattern    qd_dkGray;
  90.     Pattern    qd_ltGray;
  91.     Pattern    qd_gray;
  92.     Pattern    qd_black;
  93.     Pattern    qd_white;
  94.     GrafPtr    qd_thePort;
  95. } qd;
  96.  
  97. #define thePort        qd.qd_thePort
  98. #define white        qd.qd_white
  99. #define black        qd.qd_black
  100. #define gray        qd.qd_gray
  101. #define ltGray        qd.qd_ltGray
  102. #define dkGray        qd.qd_dkGray
  103. #define arrow        qd.qd_arrow
  104. #define screenBits    qd.qd_screenBits
  105. #define randSeed    qd.qd_randSeed
  106. #endif
  107.  
  108. static long        saveA5;
  109. static long        localA5;
  110.  
  111. static Rect srcRect = {0,0,32,32};    /* for copybits */
  112. static Rect    destRect= {0,0,32,32};
  113.  
  114. static BitMap myBitMap = {
  115.     0,                /* address */
  116.     iconRowBytes,    /* rowBytes */
  117.     0,0,32,32        /* Rect */
  118. };
  119. static BitMap myMaskMap = {
  120.     0,                /* address */
  121.     iconRowBytes,    /* rowBytes */
  122.     0,0,32,32        /* Rect */
  123. };
  124. static GrafPort    myPort;
  125.  
  126.  
  127. static pascal void INITDraw1Bit(ICONListPtr iconPtr);
  128. static pascal void INITDrawCQD(CIconHandle);
  129. static pascal void INITDrawXBit(void *icl_Ptr, short iclDepth, ICONListPtr iconPtr);
  130.  
  131. /***************************************************************************************\
  132. |                                                                                        |
  133. |    Displays the ICN# (cicn when in 4 bit mode or higher) specified by iconID.            |
  134. |                                                                                        |
  135. |    PROCEDURE ShowINIT(iconID: Integer); EXTERNAL;                                        |
  136. |                                                                                        |
  137. |    pascal void ShowINIT(short iconID);                                                    |
  138. |        extern;                                                                            |
  139. |                                                                                        |
  140. \***************************************************************************************/
  141.  
  142. pascal void ShowINIT(short iconID) {
  143.     register void *Addr3, *Addr2;
  144.     register long Data7, Data6, Data5, Data4, Data3;
  145.  
  146.     asm {
  147. ShowINIT:
  148.                 // 28E = ROM85
  149.         btst.b    #hasCQDBit,0x28E    ; try to get a color icon if CQD exists
  150.         beq        @ShowINITCQD        ; I could use SysEnvirons but I don't want to
  151.  
  152. ShowINIT1Bit:
  153.         clr.l    -(sp)                ; try to get the icon resource
  154.         move.l    #'ICN#',-(sp)
  155.         move.w    iconID(a6),-(sp)
  156.         GetResource
  157.         move.l    (sp)+,d0
  158.         beq        @ShowINITError        ; can't get it, give up
  159.  
  160.         move.l    d0,-(sp)            ; leave handle on the stack for ReleaseResource
  161.         move.l    d0,a0
  162.         HLock
  163.         move.l    (a0),a0                ; dereference
  164.         move.l    a0,-(sp)            ; icon pointer
  165.         jsr        INITDraw1Bit        ; draw
  166.         ReleaseResource                ; release the resource
  167.         return
  168.  
  169. ShowINITCQD:
  170.         move.l    #0x40008,d2
  171.         move.l    #'icl8',d3
  172.         move.l    #'icl4',d4
  173.             // MainDevice = 0x8A4
  174.         move.l    0x8A4,a0        ; get handle to main device
  175.         move.l    (a0),a0                ; dereference
  176.         move.l    GDevice.gdPMap(a0),a0
  177.                                     ; get its pixmap handle
  178.         move.l    (a0),a0                ; dereference it
  179.         cmpi.w    #4,PixMap.pixelSize(a0)
  180.                                     ; is it deep enough for us to draw with icl4?
  181.         blt.s    @ShowINIT1Bit        ; no, go to 1-bit.
  182.                                     ; is it deep enough for us to draw with icl8?
  183.         beq.s    @SwapOrder            ; no, swap order.
  184.  
  185. tryAgain:
  186.         clr.l    -(sp)
  187.         move.l    d3,-(sp)
  188.         move.w    iconID(a6),-(sp)
  189.         GetResource
  190.         move.l    (sp)+,d1
  191.         bne.s    @FoundIc
  192.  
  193.         clr.w    d2
  194. SwapOrder:
  195.         swap    d2
  196.         beq        @tryCICN
  197.         exg        d3,d4
  198.         bra.s    @tryAgain
  199.  
  200. tryCICN:
  201.         goto    ShowINIT1Bit
  202.  
  203. FoundIc:
  204.         clr.l    -(sp)
  205.         move.l    #'ICN#',-(sp)
  206.         move.w    iconID(a6),-(sp)
  207.         GetResource
  208.         move.l    (sp)+,d0
  209.         bne.s    @FoundCompanion
  210.  
  211.         move.l    d1,-(sp)
  212.         ReleaseResource
  213.         bra        @tryCICN
  214.  
  215. FoundCompanion:        
  216.         move.l    d1,-(sp)        ; leave handle on the stack for ReleaseResource
  217.         move.l    d0,-(sp)        ; leave handle on the stack for ReleaseResource
  218.         move.l    d0,d3
  219.  
  220.         move.l    d1,a0
  221.         HLock
  222.         move.l    (a0),a0            ; dereference
  223.         move.l    a0,-(sp)        ; icl_ pointer
  224.         move.w    d2,-(sp)        ; icl_ depth
  225.         move.l    d3,a0
  226.         HLock
  227.         move.l    (a0),a0            ; dereference
  228.         move.l    a0,-(sp)        ; icon pointer
  229.         jsr        INITDrawXBit    ; draw
  230.         ReleaseResource        ; release the resource
  231.         ReleaseResource        ; release the resource
  232.         return
  233.  
  234. ShowINITError:
  235.         move.w    #8,-(sp)            ; just beep
  236.         SysBeep
  237.         return
  238.     }
  239. }
  240.  
  241. static void ShowINITCredits(void) {
  242.     asm {
  243.         dc.b    "ShowINIT by Paul Mercer"    ,0
  244.         dc.b    "Copyright 1987-1989"        ,0
  245.         dc.b    "Version of 11/25/89"        ,0
  246.         dc.b    "Modified by jbx 8/28/90"    ,0
  247.     };
  248. }
  249.  
  250. /***************************************************************************************\
  251. |                                                                                        |
  252. |    Initializes the world and sets up the drawing rectangle                                |
  253. |                                                                                        |
  254. \***************************************************************************************/
  255.  
  256. static void INITInit(void) {
  257.     asm {
  258.             // CurrentA5 = 0x904
  259.         move.l    0x904,saveA5    ; PM 10/6 save host A5
  260.         lea        localA5,a5            ; PM7/21
  261.         move.l    a5,0x904
  262.         pea        qd.thePort                ; PM 10/6 use a5 reference instead of a6
  263.         InitGraf                    ; fixes color bug as per DA@ICOM
  264.         pea        myPort
  265.         OpenPort
  266.  
  267.         move.w    myV,d0            ; get my v var
  268.         rol.w    #1,d0            ; compare against checksum
  269.         eor.w    #checksumConst,d0
  270.         cmp.w    myVCheck,d0
  271.         beq.s    @ScratchVOK        ; checks, so go on test my h var
  272.  
  273.         move.w    myPort.portBits.bounds.bottom,d0 ; else initialize as first time
  274.         sub.w    #160,d0
  275.         sub.w    #bottomEdge,d0
  276.         move    d0,myV
  277. ScratchVOK:
  278.         move.w    myH,d0            ; get my h var
  279.         rol.w    #1,d0            ; compare against checksum
  280.         eor.w    #checksumConst,d0
  281.         cmp.w    myHCheck,d0
  282.         beq.s    @ScratchHOK        ; checks, so go on
  283.         move    #firstX,myH        ; else initialize as first time
  284. ScratchHOK:
  285.         move.l    myV,d0            ; trickery - high word is V, lo word is H.
  286.  
  287.         move.w    d0,d1            ; get future position
  288.         add.w    #iconWidth,d1    ; compute future rect right
  289.         cmp.w    myPort.portBits.bounds.right,d1 ; compare to main screen right
  290.         blt.s    @DontChangeLine    ; smaller - do nothing
  291.  
  292.         move.w    myV,d0            ; decrement Y value
  293.         subi.w    #defaultMoveY,d0
  294.         move.w    d0,myV
  295.         move.w    #firstX,myH        ; set X to initial value
  296.  
  297.         move.l    myV,d0
  298. DontChangeLine:
  299.         lea        destRect,a0
  300.         move.l    d0,(a0)+
  301.         move.l    d0,(a0)
  302.     }
  303. }
  304.  
  305. /***************************************************************************************\
  306. |                                                                                        |
  307. |    Based on the mask, advances the icon drawing position and adjusts destRect            |
  308. |                                                                                        |
  309. \***************************************************************************************/
  310.  
  311. static void MaskAdjust(void) {
  312.     asm {
  313.         lea        myMaskMap,a0
  314.         move.l    (a0)+,a1        ; baseAddr
  315.         move.w    (a0)+,d0        ; rowBytes
  316.         move.w    4(a0),d1        ; bottom
  317.         move.w    6(a0),d2        ; right
  318.         sub.w    (a0)+,d1        ; top - d1 now has height.
  319.         sub.w    (a0)+,d2        ; left - d2 now has width.
  320.         add.w    d1, destRect.bottom
  321.         add.w    d2, destRect.right
  322.         cmpi.w    #4,d0            ; is rowBytes 4? Might not be on a color icon!
  323.         beq.s    @four
  324.         add.w    d2,myH            ; so assume the icon is properly done,
  325.         goto    done            ; without any mask holes.
  326.     four:
  327.         add.w    #32,myH            ; assume the icon is normal.
  328.         moveq    #0,d0            ; d0 accumulates the mask columns.
  329.         subq.w    #1,d1
  330.         bmi.s    @out            ; oops, no height, we're outa here.
  331.  
  332.     ol:    or.l    (a1)+,d0
  333.         dbra    d1,    @ol
  334.  
  335.         ; OK, now d0's bits correspond to the columns of the mask.
  336.         ; make sure there really is a mask...
  337.         tst.l    d0
  338.         bne.s    @lft
  339.     out:return            ; and if not, we're outa here!
  340.  
  341.         ; first thing, we shift the icon to the left for every empty high bit:
  342.     ll:    subq.w    #1,destRect.left
  343.         subq.w    #1,destRect.right
  344.         asl.l    #1,d0
  345.     lft:bpl.s    @ll
  346.  
  347.         ; OK, now the icon is properly positioned.  Now we check for empty space on
  348.         ; on the right, which we can use to properly figure the destination rectangle:
  349.     rl:    ror.l    #1,d0
  350.         bmi.s    @done
  351.         subq.w    #1,myH
  352.         bra.s    @rl
  353.     }
  354.     done:
  355.         myH += 8;
  356. }
  357.  
  358. /***************************************************************************************\
  359. |                                                                                        |
  360. |    Cleans up the work done by INITInit and advances the icon drawing position            |
  361. |                                                                                        |
  362. \***************************************************************************************/
  363.  
  364. static void INITCleanup(void) {
  365.     asm {
  366.         move.w    myH,d0            ; get current position
  367.         rol.w    #1,d0            ; recompute h checksum
  368.         eor.w    #checksumConst,d0
  369.         move.w    d0,myHCheck        ;  and save it
  370.  
  371.         move    myV,d0            ; same for v checksum
  372.         rol.w    #1,d0
  373.         eor.w    #checksumConst,d0
  374.         move.w    d0,myVCheck
  375.  
  376.         pea        myPort            ; *** (DBA) I think that QuickDraw leaves handles around.
  377.         ClosePort                ; *** (DBA) Too bad we can't get rid of them...
  378.  
  379.         move.l    saveA5,a5        ; PM 10/6 restore host A5
  380.         move.l    a5,0x904
  381.     }
  382. }
  383.  
  384. /***************************************************************************************\
  385. |                                                                                        |
  386. |    display the ICN# pointed to by iconPtr and move the pen horizontally by moveX        |
  387. |     pass a -1 in moveX to move the standard amount, moveX should be 40 for most ICN#'s    |
  388. |                                                                                        |
  389. |    PROCEDURE INITDraw1Bit(iconPtr: ICONListPtr); EXTERNAL                                |
  390. |                                                                                        |
  391. |    pascal void INITDraw1Bit(ICONListPtr iconPtr);                                        |
  392. |                                                                                        |
  393. \***************************************************************************************/
  394.  
  395. static pascal void INITDraw1Bit(ICONListPtr iconPtr) {
  396.     INITInit();            /* initialize for drawing. */
  397.  
  398.     myBitMap.baseAddr  = (void *)iconPtr->Icon;
  399.     myMaskMap.baseAddr = (void *)iconPtr->IconMask;
  400.  
  401.     MaskAdjust();
  402.  
  403.     CopyMask(&myBitMap, &myMaskMap, &myPort.portBits, &srcRect, &srcRect, &destRect);
  404.  
  405.     INITCleanup();    /* cleanup, advance icon location */
  406. }
  407.  
  408.  
  409. /***************************************************************************************\
  410. |                                                                                        |
  411. |    display the Icl pointed to by iclPtr and move the pen horizontally by moveX            |
  412. |     pass a -1 in moveX to move the standard amount, moveX should be 40 for most ICN#'s    |
  413. |                                                                                        |
  414. |    PROCEDURE INITDrawXBit(iclPtr: icl_Ptr; iclDepth: Integer;                             |
  415. |                iconPtr: ICONListPtr); EXTERNAL;                                        |
  416. |                                                                                        |
  417. |    pascal void INITDrawXBit(icl_Ptr, iclDepth, moveX)                                    |
  418. |        icl_Ptr *iclPtr;                                                                |
  419. |        short iclDepth;                                                                    |
  420. |        ICONList *iconPtr;                                                                |
  421. |        extern;                                                                            |
  422. |                                                                                        |
  423. \***************************************************************************************/
  424.  
  425. static pascal void INITDrawXBit(void *icl_Ptr, register short iclDepth, ICONListPtr iconPtr) {
  426.     PixMapHandle pmh;
  427.     register PixMapPtr pmp;
  428.  
  429.     if (!(pmh = NewPixMap())) {
  430.         INITDraw1Bit(iconPtr);
  431.     } else {
  432.         INITInit();            /* initialize for drawing */
  433.         HLock((Handle) pmh);
  434.         pmp = *pmh;
  435.         DisposeHandle((Handle) pmp->pmTable);
  436.         pmp->pmTable = (CTabHandle) RGetResource('clut', iclDepth);
  437.         pmp->baseAddr = icl_Ptr;
  438.         pmp->rowBytes = 0x8000 | (iclDepth * iconRowBytes);
  439.         pmp->bounds = srcRect;
  440.         pmp->pixelType = chunky;
  441.         pmp->pixelSize = iclDepth;
  442.         pmp->cmpCount = 1;
  443.         pmp->cmpSize = iclDepth;
  444.  
  445.         myMaskMap.baseAddr = (void *)iconPtr->IconMask;
  446.         MaskAdjust();
  447.         
  448.         CopyMask((BitMap *)pmp, &myMaskMap, &myPort.portBits, &srcRect, &srcRect, &destRect);
  449.  
  450.         pmp->pmTable = (void *)NewHandle(0);
  451.         DisposPixMap(pmh);
  452.  
  453.         INITCleanup();        /* cleanup, advance icon location */
  454.     }
  455. }